import { WXChannel, ALPChannel, UPIChannel } from '@shared/interfaces/acquirer'
import { parseCurValue, numScale } from 'app/utils/helpers'
import { TemplateRef } from '@angular/core'

export const getWXPChannelColumns = (channel: WXChannel) => {
  return [
    [
      {
        span: 8,
        label: 'chanCode',
        value: channel.chanCode,
      },
      {
        span: 8,
        label: 'WeChat Merchant ID',
        value: channel.chanMerID,
      },
      {
        span: 8,
        label: 'Channel Merchant Name',
        value: channel.chanMerName,
      },
    ],
    [
      {
        span: 8,
        label: 'Transaction Fee',
        value: numScale(channel.fee, 2) + '%',
      },
      {
        span: 8,
        label: 'Transaction Currency',
        value: parseCurValue(channel.currencies),
      },
      {
        span: 8,
        label: 'API Secret',
        value: channel.signKey,
      },
    ],
    [
      {
        span: 8,
        label: 'API Certificate',
        value: channel.publicKey,
      },
      {
        span: 6,
        label: 'API Certificate Private Key',
        value: channel.privateKey,
      },
      {
        span: 6,
        label: 'WeChat APP ID',
        value: channel.appID,
      },
      {
        span: 4,
        label: '操作',
        labelI18n: 'GENERAL.INFO.OPERATION',
        operate: true,
        acl: ['api.delete.toz.institution.one.channel'],
      },
    ],
  ]
}

export const getALPChannelColumns = (channel: ALPChannel, operate?: TemplateRef<void>) => {
  if (!channel.sftp) {
    channel.sftp = {
      username: '',
      password: '',
      filePath: '',
    }
  }
  return [
    [
      {
        span: 8,
        label: 'chanCode',
        value: channel.chanCode,
      },
      {
        span: 8,
        label: 'Alipay Partner ID',
        value: channel.chanMerID,
      },
      {
        span: 8,
        label: 'Channel Merchant Name',
        value: channel.chanMerName,
      },
    ],
    [
      {
        span: 8,
        label: 'Transaction Fee',
        value: numScale(channel.fee, 2) + '%',
      },
      {
        span: 8,
        label: 'Transaction Currency',
        value: parseCurValue(channel.currencies),
      },
      {
        span: 8,
        label: 'Settlement Currency',
        value: channel.settleCurrency,
      },
    ],
    [
      {
        span: 8,
        label: 'MD5 Key',
        value: channel.signKey,
      },
      {
        span: 8,
        label: 'SFTP username',
        value: channel.sftp.username,
      },
      {
        span: 8,
        label: 'SFTP path',
        value: channel.sftp.filePath,
      },
    ],
    [
      {
        span: 8,
        label: 'Alipay Partner ID Type: Pre-authorization',
        value: channel.isSupportPreAuth,
      },
      {
        span: 8,
        label: 'alpAppID',
        value: channel.appID,
      },
      {
        span: 8,
        label: 'Alipay RSA Public Key',
        value: channel.publicKey,
      },
    ],
    [
      {
        span: 20,
        label: 'RSA Private Key',
        value: channel.privateKey,
      },
      {
        span: 4,
        label: '操作',
        labelI18n: 'GENERAL.INFO.OPERATION',
        operate: true,
        acl: ['api.delete.toz.institution.one.channel'],
      },
    ],
  ]
}

export const getUPIChannelColumns = (channel: UPIChannel, operate?: TemplateRef<void>) => {
  return [
    [
      {
        span: 6,
        label: 'chanCode',
        value: channel.chanCode,
      },
      {
        span: 6,
        label: 'Acquiring IIN',
        value: channel.chanMerID,
      },
      {
        span: 6,
        label: 'Forwarding IIN',
        value: channel.chanMerIDSecondary,
      },
      {
        span: 6,
        label: 'Channel Merchant Name',
        value: channel.chanMerName,
      },
    ],
    [
      {
        span: 8,
        label: 'Transaction Fee',
        value: numScale(channel.fee, 2) + '%',
      },
      {
        span: 8,
        label: 'Transaction Currency',
        value: parseCurValue(channel.currencies),
      },
      {
        span: 8,
        label: 'Settlement Currency',
        value: channel.settleCurrency,
      },
    ],
    [
      {
        span: 8,
        label: 'ownerInsCode',
        value: channel.chanInsCode,
      },
      {
        span: 8,
        label: 'Channel Sign Public Key ID',
        value: channel.signKeyID,
      },
      {
        span: 8,
        label: 'Channel Encryption Public Key ID',
        value: channel.encryptKeyID,
      },
    ],
    [
      {
        span: 10,
        label: 'Channel Sign Public Key',
        value: channel.signKey,
      },
      {
        span: 10,
        label: 'Channel Encryption Public Key',
        value: channel.encryptKey,
      },
      {
        span: 4,
        label: '操作',
        labelI18n: 'GENERAL.INFO.OPERATION',
        operate: true,
        acl: ['api.delete.toz.institution.one.channel'],
      },
    ],
  ]
}

export const getTRUChannelColumns = (channel: UPIChannel, operate?: TemplateRef<void>) => {
  return [
    [
      {
        span: 18,
        label: 'chanCode',
        value: channel.chanCode,
      },
      {
        span: 6,
        label: '操作',
        labelI18n: 'GENERAL.INFO.OPERATION',
        operate: true,
        acl: ['api.delete.toz.institution.one.channel'],
      },
  ]
]
}
